import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
import type { StoreInfo } from '@/Interface/StoreInfoInterface'
import { createJSONStorage, persist } from 'zustand/middleware'

type BasicDataState = {
  basicData: StoreInfo | null,
  setBasicData: (data: StoreInfo) => void
}

export const useBasicDataStore = create<BasicDataState>()(
  persist(
    immer((set) => ({
      basicData: null,
      setBasicData: (data) =>
        set((state) => { state.basicData = data })
    })),
    {
      name: 'basic-data',
      storage: createJSONStorage(() => sessionStorage),
    }
  )
)